<template>
  <div id="particulars">
    <v-detail :detailData="inputData"
              :inputConfig="inputConfig"
              :rules="rules"
              @changeData="changeData"
              @pop="setdata"
              ref="input"></v-detail>
  </div>
</template>

<script>
import detail from "commons/Detail";
import baseMixin from "@/mixins/BaseMixin";

export default {
  name: "particulars",
  props: {
    inputData: {
      type: Object
    }
  },
  mixins: [baseMixin],
  data () {
    return {
      rules: {
        storerkey: [
          { required: true, trigger: 'blur' },
        ],
        sku: [
          { required: true, trigger: 'blur' },
        ],
        altsku: [
          { required: true, trigger: 'blur' },
        ],
        type: [
          { required: true, trigger: 'blur' },
        ]
      },
      flag: true,
    }
  },
  computed: {
    inputConfig () {
      return [
        [
          {
            type: "table",
            label: this.$t('config.shipper'),
            props: "storerkey",
            tableConfig: [
              {
                label: this.$t('config.shipper'),
                prop: "storerkey",
                input: "input",
              },
              {
                label: this.$t('config.company'),
                prop: "company",
                input: "input",
              },
              {
                label: this.$t('config.city'),
                prop: "city",
                input: "input",
              },
              {
                label: this.$t('config.provice'),
                prop: "state",
                input: "input",
              },
              {
                label: this.$t('config.postcode'),
                prop: "zip",
                input: "input",
              },
              {
                label: this.$t('config.contact'),
                prop: "contact",
                input: "input",
              },
              {
                label: this.$t('config.phone'),
                prop: "phone",
                input: "input",
              },
            ],
            url: `/queryStorer/1/?/${this.$store.state.wms}`,
            disabled: this.flag
          },
          {
            type: "table",
            label: this.$t('config.sku'),
            props: "sku",
            tableConfig: [
              {
                label: this.$t('config.sku'),
                prop: "sku",
                input: "input",
              },
              {
                label: this.$t('common.desc'),
                prop: "descr",
                input: "input",
              },
              {
                label: this.$t('config.shipper'),
                prop: "storerkey",
                input: "input",
              },
              {
                label: this.$t('config.packaging'),
                prop: "packkey",
                input: "input",
              },
              {
                label: this.$t('config.boxGroup'),
                prop: "cartongroup",
                input: "select",
                options: this.getOptions("queryCartonizationDropDown")
              },
              {
                label: this.$t('config.allocaStrategy'),
                prop: "strategykey",
                input: "select",
                options: this.getOptions("queryAllocatestrategyDropDown")
              },
              {
                label: this.$t('config.putawayStrategy'),
                prop: "putawaystrategykey",
                input: "select",
                options: this.getOptions("queryPutawaystrategyDropDown")
              },
              {
                label: this.$t('config.batchValidate'),
                prop: "lottablevalidationkey",
                input: "select",
                options: this.getOptions("queryLottablevalidationDropDown")
              },
              {
                label: this.$t('config.area'),
                prop: "putawayzone",
                input: "select",
                options: this.getOptions("queryPutawayzoneDropDown")
              }
            ],
            url: `/querySkuOfStorerkey/?/${this.$store.state.wms}/${this.inputData.storerkey}`,
            disabled: this.flag
          },
          {
            type: "input",
            label: this.$t('config.skuDesc'),
            props: "skudescr",
            disabled: true
          },
          {
            type: "input",
            label: this.$t('config.spareGoods'),
            props: "altsku",
            disabled: this.flag
          },
          {
            type: "table",
            label: this.$t('config.packaging'),
            props: "packkey",
            tableConfig: [
              {
                label: this.$t('config.packaging'),
                prop: "packkey",
                input: "input",
              },
              {
                label: this.$t('common.desc'),
                prop: "packdescr",
                input: "input",
              }
            ],
            url: `/queryPack/${this.$store.state.wms}/`,
          },
        ],
        [
          {
            type: "select",
            label: this.$t('common.type'),
            props: "type",
            options: this.getOptions("querycodeLkup/ALTSKUTYPE")
          },
          {
            type: "table",
            label: this.$t('config.supplier'),
            props: "vendor",
            tableConfig: [
              {
                label: this.$t('config.supplier'),
                prop: "storerkey",
                input: "input",
              },
              {
                label: this.$t('config.company'),
                prop: "company",
                input: "input",
              },
              {
                label: this.$t('config.city'),
                prop: "city",
                input: "input",
              },
              {
                label: this.$t('config.provice'),
                prop: "state",
                input: "input",
              },
              {
                label: this.$t('config.postcode'),
                prop: "zip",
                input: "input",
              },
              {
                label: this.$t('config.contact'),
                prop: "contact",
                input: "input",
              },
              {
                label: this.$t('config.phone'),
                prop: "phone",
                input: "input",
              },
            ],
            url: `/queryStorer/5/?/${this.$store.state.wms}`,
          },
          {
            type: "select",
            label: this.$t('config.defaultMeasureUnit'),
            props: "defaultuom",
            options: [
              { code: 'EA', description: 'EA' },
              { code: 'IP', description: 'IP' },
              { code: 'CA', description: 'CA' }
            ]
          }
        ],
        [
          {
            type: "input",
            label: "udf1",
            props: "udf1",
          },
          {
            type: "input",
            label: "udf2",
            props: "udf2",
          },
          {
            type: "input",
            label: "udf3",
            props: "udf3",
          },
          {
            type: "input",
            label: "udf4",
            props: "udf4",
          },
          {
            type: "input",
            label: "udf5",
            props: "udf5",
          }
        ],
      ]
    }
  },
  methods: {
    setdata (data, id, close, listId) {
      if (listId == "0") {
        if (id == "0") {
          this.inputData.storerkey = data.storerkey;
        } else if (id == "1") {
          this.inputData.sku = data.sku;
          this.inputData.skudescr = data.descr;
        } else if (id == "4") {
          this.inputData.packkey = data.packkey;
        }
      } else if (listId == "1") {
        this.inputData.vendor = data.storerkey;
      }

      close(false);
    },
    changeData (obj, prop, data) {
      if (prop == "storerkey") {
        this.$api.get(`/isExists/1/${data}/${this.$store.state.wms}`).then(res => {
          
            if (res.bean <= 0) {
              this.$message.error(this.$t('config.nullShipper') + data);
              this.inputData[prop] = "";
            }
          
        }).catch(e => {
          this.$message.error(e);
        })
      }

    }
  },
  mounted () {
    if (Object.keys(this.$store.state.skip).length !== 0) {
      let data = this.$store.state.skip;
      if (data.newFlag) {
        this.flag = false;
      } else {
        this.flag = true;
      }
    } else if (this.$store.state.newFlag) {
      this.flag = false;
    } else {
      this.flag = true;
    }
  },
  watch: {},
  components: {
    "v-detail": detail
  },
}
</script>

<style scoped>
</style>
